﻿using System;
using System.ComponentModel;

namespace XSerializer.UnitTests.Sample
{
    public abstract class BaseClass : INotifyPropertyChanged, IDisposable
    {
        protected bool disposed = false;

        /// <summary>
        /// Event Handler for Property Changed
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Raised Event
        /// </summary>
        /// <param name="propertyName">Name of the Property</param>
        protected void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler propertyChanged = PropertyChanged;
            if ((propertyChanged != null))
            {
                propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        /// <summary>
        /// Dispose() calls Dispose(true)
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// NOTE: Leave out the finalizer altogether if this class doesn't 
        /// own unmanaged resources itself, but leave the other methods
        /// exactly as they are.
        /// </summary>
        ~BaseClass()
        {
            // Finalizer calls Dispose(false)
            Dispose(false);
        }

        /// <summary>
        ///  Clean-up code for IDisposable
        /// </summary>
        /// <param name="disposing">If true only managed Code</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    // Free other state (managed objects).
                }

                disposed = true;
            }
        }
    }
}
